package router

import (
	"github.com/flipped-aurora/gin-vue-admin/server/middleware"
	"github.com/flipped-aurora/gin-vue-admin/server/plugin/gva_intelligent_form/api"
	"github.com/gin-gonic/gin"
)

type IntelligentFormRouter struct{}

// InitIntelligentFormRouter 初始化智能表单路由
func (r *IntelligentFormRouter) InitIntelligentFormRouter(Router *gin.RouterGroup) {
	intelligentFormRouter := Router.Group("intelligent-form")
	intelligentFormApi := api.ApiGroupApp.IntelligentFormApi
	intelligentFormSubmissionApi := api.ApiGroupApp.IntelligentFormSubmissionApi

	{
		// 需要认证的路由
		intelligentFormRouterWithAuth := intelligentFormRouter.Group("").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
		{
			// 表单管理路由
			intelligentFormRouterWithAuth.POST("form/create", intelligentFormApi.CreateIntelligentForm)   // 创建表单
			intelligentFormRouterWithAuth.PUT("form/update", intelligentFormApi.UpdateIntelligentForm)    // 更新表单
			intelligentFormRouterWithAuth.DELETE("form/delete", intelligentFormApi.DeleteIntelligentForm) // 删除表单
			intelligentFormRouterWithAuth.GET("form/detail", intelligentFormApi.GetIntelligentForm)       // 获取表单详情
			intelligentFormRouterWithAuth.GET("form/list", intelligentFormApi.GetIntelligentFormList)     // 获取表单列表
			intelligentFormRouterWithAuth.POST("form/publish", intelligentFormApi.PublishIntelligentForm) // 发布表单
			intelligentFormRouterWithAuth.POST("form/close", intelligentFormApi.CloseIntelligentForm)     // 关闭表单

			// 提交记录管理路由
			intelligentFormRouterWithAuth.GET("submission/list", intelligentFormSubmissionApi.GetSubmissionList)     // 获取提交记录列表
			intelligentFormRouterWithAuth.GET("submission/detail", intelligentFormSubmissionApi.GetSubmission)       // 获取提交记录详情
			intelligentFormRouterWithAuth.DELETE("submission/delete", intelligentFormSubmissionApi.DeleteSubmission) // 删除提交记录
			intelligentFormRouterWithAuth.GET("submission/export", intelligentFormSubmissionApi.ExportSubmissions)   // 导出提交数据
		}

		// 公开访问的路由（不需要认证）
		intelligentFormPublicRouter := intelligentFormRouter.Group("public")
		{
			intelligentFormPublicRouter.GET("form/:id", intelligentFormApi.GetPublicForm)       // 获取公开表单
			intelligentFormPublicRouter.POST("submit", intelligentFormSubmissionApi.SubmitForm) // 提交表单
		}

		// 生成表单专用的公开路由（无需认证）
		intelligentFormGeneratedRouter := intelligentFormRouter.Group("generated")
		{
			intelligentFormGeneratedRouter.GET("form/:id", intelligentFormApi.GetGeneratedForm)             // 获取生成的表单
			intelligentFormGeneratedRouter.POST("submit", intelligentFormSubmissionApi.SubmitGeneratedForm) // 提交生成的表单
		}
	}
}
